﻿package javacpp;   //切记不能修改包名(jin调用，包的路径在编译时已经固定)

import java.io.Console;
import java.lang.Thread;

public class sdk extends Thread{
    static{
        System.loadLibrary("sdk");
    }
	public native String sdkcommand(String cmd);
    public native String sdknotify();
	public native int sdkpushstream(int port,short sample[]);  //sample count is 480,16bit short sample

	@Override
    public void run(){
		/*
		//push audio stream to virtual sound-card，samplerate 48khz，mono 16 bit deep
		int myret = 0;
		int myport = 101;
		short[] mysample = new short[480];
		for(short i = 0;i<480;i++)
		{
			mysample[i] = i;
		}
		//return 0 correct，1 sound-card not exist
		myret = mysdk.sdkpushstream(myport, mysample);
		*/

		int nID = 1;
		while (true) {
			try {
				Thread.sleep(5000);
			} 
			catch (InterruptedException e) {
				e.printStackTrace();
			}
			String cmd = String.format("tts -id %d -r 1 -l 1 -d 1 -v 20 -s @$北猎广播@$", nID++);
			sdkcommand(cmd);
		}

		
	}
	public static void main(String[] args){
		Console console = System.console();
		if(console!=null){
			console.printf("Console is available.");
		}
		//create sdk server
		sdk mysdk = new sdk();
		
		//system init
		String ret = mysdk.sdkcommand("init -node 300 -ip 192.168.0.110 -path C:/Users/Administrator/Documents/ZIBON/AudioServer/config/ -debug");
		console.printf(ret);

		//start the test thread
		//mysdk.start();

		//test play local file
		mysdk.sdkcommand("play -id 1 -s test.wav -d 1 -v 20");

		//test the tts
		//mysdk.sdkcommand("tts -id 1 -r 1 -l 1 -d 1 -v 80 -s @$北猎广播语音合成测试@$");

		//test play local stream
		//mysdk.sdkcommand("live -id 1 -s 101 -d 1");

		//get the sdk notify
		while(true){
			System.out.printf("\n");
			System.out.printf(mysdk.sdknotify());
		}
        
	}
}
